﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
   public class FtpClient
    {


       public void Mess() { Console.WriteLine("TEST"); }

        public string connect (string strHost, int NumberPort, string UserName, string PassWord)
        {
            try
            {
                FtpWebRequest request = (FtpWebRequest)WebRequest.Create(strHost);

                Console.WriteLine(" Go ");
                Console.ReadLine();
                request.Method = WebRequestMethods.Ftp.ListDirectory;

                String encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(UserName + ":" + PassWord));
                request.Credentials = new NetworkCredential(UserName, PassWord);

               
                request.Headers.Add("Authorization", "Basic " + encoded);
                request.Credentials = new NetworkCredential(UserName, PassWord);
                

                Console.WriteLine(" Step 2");
                Console.ReadLine();

                // Получаем ответ
                FtpWebResponse response = (FtpWebResponse)request.GetResponse();

                Console.WriteLine(" Step 3 ");
                Console.ReadLine();

                String html = new StreamReader(response.GetResponseStream(), Encoding.UTF8).ReadToEnd();
                Console.WriteLine(" Step 4 ");
                Console.ReadLine();

                Console.WriteLine(html);
                response.Close();
            }
            catch (Exception e) 
            {
                Console.WriteLine(e);
            }
          
            string establish = "to" + strHost + "established connection ";
            //Console.WriteLine (establish);
            //return connection established or not
            return establish;

        }
    }
}
